﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Setting_do_GetDeptInfo : SessionPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"] + "";

        if (!string.IsNullOrEmpty(id))
        {
            string dataString = GetDeptInfo(id);

            if (!string.IsNullOrEmpty(dataString))
            {
                Response.ContentType = "text/plain";
                Response.Write(dataString);
            }
        }
        else
            Response.End();
    }

    private string GetDeptInfo(string deptID)
    {
        /**
             * res = '[' 
             * res += '{ "parentID": "", "parentName": "" }' 
             * res += ']'
             */
        try
        {

            string parentID = "0", parentName = "所有部门";
            LogicLayer mgr = new LogicLayer();
            SYS_Department dept = mgr.GetSYS_Department(deptID);
            if (dept != null)
            {
                SYS_Department deptParent = mgr.GetSYS_Department(dept.ParentID);
                if (deptParent != null)
                {
                    parentID = deptParent.DeptID;
                    parentName = deptParent.DeptName;
                }
            }

            string result = "[";
            result += "{  \"parentID\": \"" + parentID + "\", \"parentName\": \"" + parentName + "\" }";
            result += "]";

            return result;
        }
        catch
        {
            return string.Empty;
        }
    }
}